package datestructuresjava.shuzuerfenfachazhao;

public class Demo2 {
    public static void main(String[] args) {
        int[] arr = {10, 30, 45, 60, 79, 88, 100, 104, 200};
        int index = searchNumber(arr, 0, arr.length - 1, 88);
        if (index==-1){
            System.out.println("在数组中没有找到该数字");
        }else {
            System.out.println("查找的数字在数组中的索引为"+index);
        }

    }

    private static int searchNumber(int[] arr, int left, int right, int num) {
        int mid = (left + right) / 2;
        while (left <= right) {
            if (arr[mid] == num) {
                return mid;
            } else if (arr[mid] < num) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
            mid = (left + right) / 2;
        }
        return -1;
    }


}





